import { Extension } from '@tiptap/core'

export const FontMetaExtension = Extension.create({
  addGlobalAttributes() {
    return [
      {
        types: ['text', 'paragraph'],
        attributes: {
          fontSize: {
            default: null,
            parseHTML: element => element.dataset.fontSize,
            renderHTML: attributes => {
              if (!attributes.fontSize) return {}
              return {
                'data-font-size': attributes.fontSize,
                style: `font-size: ${attributes.fontSize}`
              }
            }
          },
          docFont: {
            default: null,
            parseHTML: element => element.dataset.docFont,
            renderHTML: attributes => ({
              'data-doc-font': attributes.docFont
            })
          }
        }
      }
    ]
  }
})